package _interview100;

/**
 * 45. 跳跃游戏 II
 */
public class No45 {
    public int jump(int[] nums) {
        if (nums.length == 1) return 0;
        int ans = 1, maxIndex = 0;
        while (maxIndex + nums[maxIndex] < nums.length - 1) {
            ans++;
            int len = nums[maxIndex] + maxIndex;
            for (int i = maxIndex; i <= len; i++) {
                if (i + nums[i] > maxIndex + nums[maxIndex]) {
                    maxIndex = i;
                }
            }
        }
        return ans;
    }
}
